package com.example.fist.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 过滤器，负责添加返回头，跨域
 */
@WebFilter(urlPatterns = "/*", filterName = "logFilter2")
public class fieter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest request=(HttpServletRequest) servletRequest;
        request.setCharacterEncoding("utf-8");
        HttpServletResponse response=(HttpServletResponse) servletResponse;
        response.setHeader("Access-Control-Allow-Credentials", " true");
        response.setHeader("Access-Control-Allow-Origin",  request.getHeader("Origin"));
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
